<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
	<title>Home</title>
	
	<link type="text/css" rel="stylesheet" href="<c:url value="/resources/main.css" />">
	<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>

	
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
	<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
	
	<script type="text/javascript">
		$(document).ready(function(){
			$('#lookupButton').click(function(){
				var mark = $("#mark").val();
				if(mark == '') {
					alert('Please provide aircraft mark');
					return;
				}
				$.post('<c:url value="/aircraft/details"/>', { mark : mark }, function(data) {
					$('#manufacturer').val(data.manufacturer);
					$('#model').val(data.model);
					$('#operatorName').val(data.operatorName);
					$('#serialNumber').val(data.serialNumber);
				});
			});
		});
	</script>
	
</head>
<body>

	<div class="box">
        <form:form method="post" modelAttribute="aircraft" action="${pageContext.request.contextPath}/aircraft/add">
        	<table>
            	<tr><td>Aircraft Reg. Mark</td><td><form:input path="mark" size="8" /><input id="lookupButton" type="button" value="Lookup" class="button"></td></tr>
            	<tr><td>Aircraft Manufacturer</td><td><form:input path="manufacturer" size="50" /></td></tr>
            	<tr><td>Aircraft Model</td><td><form:input path="model" /></td></tr>
            	<tr><td>Aircraft Operator</td><td><form:input path="operatorName" size="50" /></td></tr>
            	<tr><td>Aircraft Serial Number</td><td><form:input path="serialNumber"/></td></tr>
            	<tr><td><input type="submit" class="button"/></td></tr>
            </table>
        </form:form>
	</div>

	<br/>

	<div class="box">
		<br/><a href="<c:url value='/aircraft/casa' />" >Update data from CASA website</a>
	</div>

</body>
</html>